package com.dream.xiaobo.dao.impl;

import com.dream.xiaobo.dao.AdminDao;
import com.dream.xiaobo.entity.User;
import com.dream.xiaobo.utils.C3P0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author xiaobo
 * @date 2021/9/4 - 13:30
 */
public class AdminDaoImpl implements AdminDao {

    private QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());

    @Override
    public User selectUserByName(String username) throws SQLException {

        String sql = "SELECT u_id AS uId, u_name AS uName,u_password As uPassword FROM " +
                "user WHERE u_name = ?";

        User admin = queryRunner.query(sql, new BeanHandler<>(User.class), username);

        return admin;
    }
}
